# -*- coding: UTF-8 -*-

from email.mime.text import MIMEText
from email.header import Header
import smtplib


def sendEmail(email_content, user_name, person_email):
    # 输入Email地址和口令:
    from_addr = "294010445@qq.com"
    password = "fcxcbhbscnvycaci"
    to_addr = person_email
    # 输入SMTP服务器地址:
    smtp_server = "smtp.qq.com"

    # 组装邮件内容
    msg = MIMEText(email_content, 'html', 'utf-8')
    Subject = user_name + '自动报名完成'
    msg['From'] = from_addr
    msg['Subject'] = Header(Subject, 'utf-8')

    # SMTP协议默认端口是25
    server = smtplib.SMTP(smtp_server, 587)
    try:
        server.set_debuglevel(1)
        server.starttls()  # 启用 TLS 加密
        server.login(from_addr, password)
        server.sendmail(from_addr, [to_addr], msg.as_string())
        server.quit()
        print("email send end")
    except Exception as e:
        print(e)
